package com.qf.boot1.controller;

import com.baomidou.kaptcha.Kaptcha;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * @author 刘欣
 * @createTime 2023/2/1 18:56
 * @description
 */
@RestController
@RequestMapping("/kaptcha")
public class KaptchaController {
    @Autowired
    private Kaptcha kaptcha;

    @GetMapping("/render")
    public void render(HttpSession session) {
        String render = kaptcha.render();
    }

    @PostMapping("/valid")
    public void validDefaultTime(@RequestParam String code) {
        //default timeout 900 seconds
        kaptcha.validate(code);
    }

    @PostMapping("/validTime")
    public void validCustomTime(@RequestParam String code) {
        kaptcha.validate(code, 60);
    }

}
